home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_12 / guthrie / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  2.5 KB  |  91 lines

  1. /* File: MENU.C     R. Scott Guthrie            */
  2. /* This sample application demonstrates the     */
  3. /* functionality provided by the XLATE routines */
  4. /* in determining text messages at run time.    */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "xlate.h"
  10.  
  11. /******************************************/
  12. /* Present a selection menu for the user, */
  13. /* and obtain a valid input.              */
  14. /******************************************/
  15. int menu_selection(char *menu)
  16. {
  17.   /* Returns 0 if quitting, 1 if */
  18.   /* a valid selection is made.  */ 
  19.   int user_entry;  /* entered option */
  20.   int retval = 1;  /* return value   */
  21.     
  22.   /* Display the selection menu. */
  23.   do
  24.   {
  25.     printf("Meal Selection:\n\n");
  26.     printf("  1) Breakfast\n");
  27.     printf("  2) Lunch\n");
  28.     printf("  3) Dinner\n");
  29.     printf("  4) Snack\n");
  30.     printf("  Q) to quit\n");
  31.     printf("\nEnter MENU Desired: ");
  32.  
  33.     /* Get user input */
  34.     user_entry = getchar();
  35.     /* (Eat the return associated with the input) */
  36.     (void) getchar();
  37.   }      
  38.   /* Validate user's input */
  39.   while ((strchr("1234qQ", user_entry) == 0));
  40.  
  41.   /* Turn user's selection into Translate File name */
  42.   switch (user_entry)
  43.   {
  44.     case '1' :
  45.       strcpy(menu, "B_FAST");
  46.       break;
  47.     case '2' :
  48.       strcpy(menu, "LUNCH");
  49.       break;
  50.     case '3' :
  51.       strcpy(menu, "DINNER");
  52.       break;
  53.     case '4' :
  54.       strcpy(menu, "SNACK");
  55.       break;
  56.     default:
  57.       retval = 0;  /* quitting */
  58.       break;
  59.   }  /* end switch */
  60.  
  61.   return (retval);
  62. }  /* end function 'menu_selection' */
  63.     
  64. /******************************************/
  65. /* Application MAIN                       */
  66. /* This example application demonstrates  */
  67. /* the usage of the translate routines.   */
  68. /******************************************/
  69. void main()
  70. {
  71.   char menu[14];   /* Translate File name */
  72.  
  73.   while(menu_selection(menu))
  74.   {
  75.     XlateSet(menu);
  76.     printf("You have selected the %s menu.\n", Xlate("meal"));
  77.     printf("Items from this menu are available\n");
  78.     printf("%s.\n\n", Xlate("hours"));
  79.     printf("Offerings available are:\n");
  80.     printf("    %s\n", Xlate("Main Course"));
  81.     printf("    %s\n", Xlate("Side Dish"));
  82.     printf("    %s\n", Xlate("Beverage"));
  83.     printf("\n----------------------------------------\n");
  84.   }  /* end while */
  85.  
  86.   XlateFree();  /* free translate table memory */
  87.   printf("MENU PROGRAM COMPLETE\n");
  88.  
  89. } /* end main */
  90. /* end source file 'menu.c' */
  91.